//
// Created by Crestimes on 2024/11/18.
//

#ifndef CODEANALYZER_H
#define CODEANALYZER_H

#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

class CodeAnalyzer
{
public:
    explicit CodeAnalyzer(const map<string, pair<map<size_t, map<string, size_t>>, set<size_t>>> &DFAsAndEndsOfTokenType,
                          const map<string, pair<map<size_t, map<string, size_t>>, set<size_t>>> &
                              DFAsAndEndsOfAuxiliary);
    //    void generateCppExe();
    void generateCpp();
    static void generateExe(const string &path);
    // ^^^[GUI CHANGES] 将generateCppExe拆分为两个函数（由两个不同的按钮分别触发）
    static bool analyze(const string &filePath);

private:
    void generateReFunctions() const;
    void generateMainFunction() const;
    map<string, pair<map<size_t, map<string, size_t>>, set<size_t>>> DFAsAndEndsOfTokenType; // 所有正则名带_前缀的DFA图和对应的终点集
    map<string, pair<map<size_t, map<string, size_t>>, set<size_t>>> DFAsAndEndsOfAuxiliary;
    map<size_t, map<string, size_t>> mainReDFA; // 拼接了所有正则值的正则表达式对应的DFA图
    set<size_t> mainReEnds;                     // 拼接了所有正则值的正则表达式对应的DFA图的终点集
    vector<string> buffs;
};

#endif // CODEANALYZER_H
